package com.fr.chart.core;

import com.fr.base.core.GraphHelper;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.core.glyph.SoloGlyph;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Shape;
import java.awt.geom.Line2D;
import java.awt.geom.Line2D.Double;

public class LineGlyph extends SoloGlyph
{
  private static final long serialVersionUID = -8730002316936686988L;
  public static final String XML_TAG = "LineGlyph";
  private Line2D line;
  private int lineStyle = 1;
  private Color lineColor = Color.black;
  private float alpha = 1.0F;

  public LineGlyph()
  {
  }

  public LineGlyph(Line2D paramLine2D)
  {
    this.line = paramLine2D;
  }

  public Line2D getLine()
  {
    return this.line;
  }

  public void setLine(Line2D paramLine2D)
  {
    this.line = paramLine2D;
  }

  public void setLineStyle(int paramInt)
  {
    this.lineStyle = paramInt;
  }

  public int getLineStyle()
  {
    return this.lineStyle;
  }

  public void setLineColor(Color paramColor)
  {
    this.lineColor = paramColor;
  }

  public Color getLineColor()
  {
    return this.lineColor;
  }

  public void setAlpha(float paramFloat)
  {
    this.alpha = paramFloat;
  }

  public float getAlpha()
  {
    return this.alpha;
  }

  public void draw(Graphics paramGraphics)
  {
    if (this.line == null)
      return;
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    Composite localComposite = localGraphics2D.getComposite();
    Paint localPaint = localGraphics2D.getPaint();
    localGraphics2D.setComposite(AlphaComposite.getInstance(3, getAlpha()));
    localGraphics2D.setPaint(getLineColor());
    GraphHelper.drawLine(localGraphics2D, this.line.getX1(), this.line.getY1(), this.line.getX2(), this.line.getY2(), getLineStyle());
    localGraphics2D.setComposite(localComposite);
    localGraphics2D.setPaint(localPaint);
  }

  public Shape getShape()
  {
    return this.line;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str2;
      String str1 = paramXMLableReader.getTagName();
      if (str1.equals("Line"))
      {
        double d1 = 0.0D;
        double d2 = 0.0D;
        double d3 = 0.0D;
        double d4 = 0.0D;
        if ((str2 = paramXMLableReader.getAttr("x1")) != null)
          d1 = Double.valueOf(str2).doubleValue();
        if ((str2 = paramXMLableReader.getAttr("y1")) != null)
          d3 = Double.valueOf(str2).doubleValue();
        if ((str2 = paramXMLableReader.getAttr("x2")) != null)
          d2 = Double.valueOf(str2).doubleValue();
        if ((str2 = paramXMLableReader.getAttr("y2")) != null)
          d4 = Double.valueOf(str2).doubleValue();
        this.line = new Line2D.Double(d1, d3, d2, d4);
      }
      else if (str1.equals("Attr"))
      {
        if ((str2 = paramXMLableReader.getAttr("lineColor")) != null)
          setLineColor(new Color(Integer.parseInt(str2), true));
        if ((str2 = paramXMLableReader.getAttr("lineStyle")) != null)
          setLineStyle(Integer.parseInt(str2));
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("LineGlyph");
    if (this.line != null)
      paramXMLPrintWriter.startTAG("Line").attr("x1", this.line.getX1()).attr("y1", this.line.getY1()).attr("x2", this.line.getX2()).attr("y2", this.line.getY2()).end();
    paramXMLPrintWriter.startTAG("Attr");
    if (this.lineColor != null)
      paramXMLPrintWriter.attr("lineColor", getLineColor().getRGB());
    paramXMLPrintWriter.attr("lineStyle", getLineStyle());
    paramXMLPrintWriter.end();
    paramXMLPrintWriter.end();
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof LineGlyph))
      return false;
    LineGlyph localLineGlyph = (LineGlyph)paramObject;
    if (!(Equals.equals(localLineGlyph.getLine(), getLine())))
      return false;
    if (!(Equals.equals(localLineGlyph.getLineColor(), getLineColor())))
      return false;
    return (localLineGlyph.getLineStyle() == getLineStyle());
  }
}